home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / math / aprs790.zip / MIC-TEMP.BAS < prev    next >
BASIC Source File  |  1997-03-17  |  8KB  |  193 lines

  1. DECLARE SUB GetTemp (Rt!, T!)
  2.   R25 = 3000        'Thermister Value at 25 deg C
  3.   DC = .0025        'Dissipation Constant
  4.   Ts = 32           'Starting Temperature
  5.   Rc = 2543         'Initial values of voltage divider
  6.   Rb = 5572
  7.   DR = 2            'Number of series diode voltage drops
  8. GOSUB Help: Flag = -1
  9.   SCREEN 9
  10.   WIDTH 80, 43
  11. DO UNTIL a$ = "Q"
  12.   CLS
  13.   LOCATE 1, 15: PRINT "Plot of Temperature curves for the APRS MicEncoder"
  14.   LOCATE 3, 20: PRINT "for determining the values of Rc and Rb"
  15.   LOCATE 5, 20: PRINT "Rc ="; INT(Rc)
  16.   LOCATE 7, 20: PRINT "Rb ="; INT(Rb)
  17.   LOCATE 9, 20: PRINT "Diodes="; DR
  18.   LINE (150, 30)-(240, 72), 12, B
  19.  
  20.   LOCATE 5, 38: PRINT "Yellow = True  Temp"
  21.   LOCATE 7, 38: PRINT "Green  = Mic-E Temp"
  22.   LOCATE 9, 38: PRINT "R@25°C ="; R25
  23.   LINE (294, 30)-(448, 40), 14, B
  24.   LINE (294, 46)-(448, 56), 10, B
  25.   LINE (294, 62)-(448, 72), 9, B
  26.  
  27.   LOCATE 15, 35: PRINT "Error Plot °F"
  28.   LINE (266, 110)-(376, 120), 13, B
  29.   LOCATE 17, 40: PRINT "+2"
  30.   LOCATE 19, 40: PRINT " 0"
  31.   LOCATE 21, 40: PRINT "-2"
  32.   LINE (16, 132)-(640, 132), 7
  33.   LINE (16, 148)-(640, 148), 15
  34.   LINE (16, 164)-(640, 164), 7
  35.  
  36.   LINE (16, 284)-(630, 284), 15 'Zero Axis
  37.   LOCATE 40, 45: PRINT "Equivalent Source Impedance to Mic"
  38.   LINE (352, 312)-(624, 320), 11, B
  39.   GOSUB ChooseC
  40.   FOR i = 36 TO 6 STEP -2
  41.       LOCATE i, 1: PRINT (36 - i) * .5      '(1k every 2 lines)
  42.       LOCATE i, 76: PRINT 32 + (36 - i) * 5 '(10°every 2 lines)
  43.   NEXT i
  44.  
  45.   LOCATE 6, 1: PRINT "RESISTANCE": LOCATE 6, 70: PRINT "TEMPERATURE";
  46.   LOCATE 8, 5: PRINT "K Ohms": LOCATE 8, 70: PRINT "°F"
  47.   LOCATE 36, 36: PRINT "TEMPERATURE"
  48.   
  49.   FOR Tf = Ts TO Ts + 100 STEP 5
  50.       GOSUB GetRes
  51.       Re = Rb * Rt / (Rb + Rt)     'Re = Rb in parallel with Rt
  52.       Vt = (5 * Rc / (Rc + Re))    'Voltage divider eqution
  53.       Pd = ((5 - Vt) ^ 2) / Rt     'Power dissipated in Thermister
  54.       dT = Pd / DC                 'Delta Temp in °C due to dissipation
  55.       dF = dT * 9 / 5              'Delta Temp in °F due to dissipation
  56.       Tp = Tf + dF                 'Presumed temperature adjusted
  57.       Count = CINT((Vt - DR * .65) * 255 / 5)'A/D count
  58.       Xtf = 32 + (Tp - Ts) * 6'Horizontal axis
  59.       Yrt = 284 - .001 * 16 * Rt   'Res curve  16 lines= 1K
  60.       Yre = 284 - .001 * 16 * Re   'Res curve  16 lines= 1K
  61.       Ytt = 284 - .1 * 16 * (Tp - Ts)'Temp curve   16 lines= 10 deg
  62.       Yct = 284 - .1 * 16 * (Count - Ts)'A/D curve
  63.       Ydl = 148 - 8 * (Tp - Count) 'Error curve
  64.       X = Xtf * 80 / 640
  65.       IF X > 1 AND X < 77 THEN LOCATE 38, X: PRINT MID$(STR$(CINT(Tf)), 2)
  66.       IF Re > 9000 THEN LINE (Xtf0, Yrt)-(Xtf, 124), 4, BF
  67.       LINE (Xtf, 90)-(Xtf, 296), 1
  68.       LINE (Xtf0, Yrt0)-(Xtf, Yrt), 9: CIRCLE (Xtf, Yre), 2, 11
  69.       LINE (Xtf0, Ytt0)-(Xtf, Ytt), 14
  70.       LINE (Xtf0, Yct0)-(Xtf, Yct), 10
  71.       LINE (Xtf0, Ydl0)-(Xtf, Ydl), 13
  72.       Xtf0 = Xtf: Ytf0 = Ytf: Yct0 = Yct: Ydl0 = Ydl: Ytt0 = Ytt: Yrt0 = Yrt
  73.   NEXT Tf
  74.   LOCATE 43, 4: PRINT "Adjust Rc/Rb with ARROW keys.  H=Help,  M=Modify,  Q=Quit";
  75.   a$ = ""
  76.   DO WHILE a$ = ""
  77.      a$ = UCASE$(INKEY$)
  78.      IF a$ <> "" THEN
  79.         IF TIMER - LastKey < .2 THEN Factr = 1.1 ELSE Factr = 1.01
  80.         LastKey = TIMER
  81.         IF UCASE$(a$) = "Q" THEN
  82.         ELSEIF a$ = CHR$(0) + CHR$(72) THEN Rc = Rc * Factr
  83.         ELSEIF a$ = CHR$(0) + CHR$(80) THEN Rc = Rc / Factr
  84.         ELSEIF a$ = CHR$(0) + CHR$(75) THEN Rb = Rb / Factr
  85.         ELSEIF a$ = CHR$(0) + CHR$(77) THEN Rb = Rb * Factr
  86.         ELSEIF a$ = "M" THEN GOSUB Modify
  87.         ELSEIF a$ = "H" THEN GOSUB Help: a$ = "H"
  88.         END IF
  89.      END IF
  90.   LOOP
  91. LOOP
  92. END  'End of main program
  93.  
  94. GetRes: 'This calculates the RESISTANCE from the Thermister given Temp
  95.         Tk = 5 * (Tf - 32) / 9 + 273
  96.         Rt = R25 * EXP((LnA - C * LOG(Tk) + D / Tk))
  97.         RETURN
  98.  
  99. Help: CLS
  100. PRINT "Mic-Temp.exe"
  101. PRINT
  102. PRINT "The purpose of this program is to permit the selection of the best bias"
  103. PRINT "resistors for the Thermister so that the resulting 0 to 255 telemetry "
  104. PRINT "value equals the actual temperature.   Although this is not necessary,"
  105. PRINT "because APRS can accept the telemetry equations for conversion of the"
  106. PRINT "values on receive, it is desirable in most simple applications so that"
  107. PRINT "                                     the unique telemetry equations do"
  108. PRINT " 5 volts *-----*-----*               not have to be transmitted to APRS"
  109. PRINT "               |     |               over the air."
  110. PRINT "               \     \"
  111. PRINT "           Rb  /     / Thermister"
  112. PRINT "               \     \"
  113. PRINT "               |     |     .65"
  114. PRINT "               *-----*------>|-------> to Mic-E AD-2 input"
  115. PRINT "                     |     volt"
  116. PRINT "                     \     drop"
  117. PRINT "                 Rc  /"
  118. PRINT "                     \"
  119. PRINT "                     |"
  120. PRINT "         *-----------*-------------> Ground"
  121. IF Flag = 0 THEN
  122.    LOCATE 23, 1: INPUT "Hit ENTER key to continue"; a$
  123.    LOCATE 23, 1:
  124. END IF
  125. PRINT "Your OBJECTIVE is to get the GREEN line and the YELLOW line to match....."
  126. PRINT
  127. PRINT "Notice that you cannot get the curve to match at all temps at once.  The initial";
  128. PRINT "values of 2543 and 5572 are perfect between about 62 and 122°F with 2 diode"
  129. PRINT "voltage drops.  That is the best I could do.  You may adjust all of these values"
  130. PRINT "and modify the program as needed to suit your requirements."
  131. PRINT
  132. PRINT "The +/- 2 degree Error scale only applies to the purple error curve..."
  133. PRINT "Rapidly pressing the ARROW keys within .3 seconds speeds Resistance changes."
  134. PRINT : PRINT
  135. PRINT "Again, Your OBJECTIVE is to get the GREEN line and the YELLOW line to match..."
  136. PRINT : PRINT
  137.  
  138. LOCATE 1, 38: PRINT SPACE$(27); "Mic-TEMP.EXE"
  139. LOCATE 2, 38: PRINT SPACE$(39)
  140. IF Flag THEN P = 41 ELSE P = 23
  141. LOCATE P, 1: INPUT "Hit ENTER key to continue"; a$
  142. LOCATE 3, 1
  143. RETURN
  144.  
  145. ChooseC:
  146.   IF Ts >= 32 THEN
  147.      LnA = 9.92949      'Rt Equation Coeffs 0-50°C
  148.      C = 3.48346
  149.      D = 2957.01
  150.   ELSE LnA = 27.80891   'Rt Equation Coeffs -50-0°C
  151.        C = 6.18843
  152.        D = 2218.28
  153.   END IF
  154.   Xtf0 = Ts
  155.   Ytf0 = 284
  156.   Yct0 = 284
  157.   Ytt0 = 284
  158.   Yrt0 = 284
  159.   Ydl0 = 150
  160.   RETURN
  161.  
  162. Modify: CLS
  163.  PRINT "This program is written for Keystone thermister RL2007-1723-103-SA available"
  164.  PRINT "from DIGIkey as part number KC004E-ND for about $2.  There are other models"
  165.  PRINT "with the same equations but with different initial values at 25°C as follows:"
  166.  PRINT
  167.  PRINT " R@25°C  Disip Const  Part No    Price"
  168.  PRINT " ------  -----------  ---------  -----"
  169.  PRINT
  170.  PRINT " 1000      .0035       KC001E-ND  $2.17  Low temps  Rb=5680, Rc=3860, 4 drops"
  171.  PRINT " 2000      .0025       KC002E-ND  $2.09"
  172.  PRINT " 2786      .0025       KC003E-ND  $2.09"
  173.  PRINT " 3000      .0025       KC004E-ND  $2.09  Warm temps Rb=6100, Rc=2600, 2 drops"
  174.  PRINT " 5000      .0010       KC005E-ND  $2.62"
  175.  PRINT "10000      .0010       KC006E-ND  $2.62"
  176.  PRINT
  177.  PRINT "Remember that the Mic-E input drive impedance should be below 10K to minimize"
  178.  PRINT "interaction between A/D inputs.   For this reason, a red line is drawn on the"
  179.  PRINT "chart showing areas where the parallel value of Rb & Rt are greater than 10k."
  180.  PRINT
  181.  PRINT : PRINT "Enter Resistance at 25°C ("; R25; ")";
  182.        INPUT X$: IF X$ <> "" THEN R25 = VAL(X$)
  183.        IF R25 < 1800 THEN DC = .0035
  184.        IF R25 > 3500 THEN DC = .001
  185.  PRINT : PRINT "Enter Number of 0.65 series diode voltage drops("; DR; ")";
  186.        INPUT X$: IF X$ <> "" THEN DR = VAL(X$)
  187.  PRINT : PRINT "Enter a different starting Temperature ("; Ts; ")";
  188.        INPUT X$: IF X$ <> "" THEN Ts = VAL(X$)
  189.        IF Ts < 0 THEN Ts = 0
  190.        IF Ts > 100 THEN Ts = 100
  191.  RETURN
  192.  
  193.